package cn.chenxiejia;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: T4
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/7 19:12
 */
public class T4 {
    static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        Thread a = new Thread(T4::add, "T1");
        a.start();
        //线程打断
        a.interrupt();
        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            try {

                lock.lockInterruptibly();
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程二");
            lock.unlock();
        }).start();
    }

    static void add() {
        try {
            lock.lock();
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("11");
        lock.unlock();
    }
}
